<template>
  <edit-dialog :centerDialogVisible="visible" :tilte="title" width="600" @Cancel="handleCancel" @Submit="handleSubmit" :disabled="loading">
    <template #content>
      <el-form :model="form" :rules="rules" ref="applyApproveFormRef" class="upload-approve-form" label-width="auto">
        <el-form-item label="延期原因" prop="deferReason">
          <el-input v-model="form.deferReason" type="textarea" rows="6" show-word-limit maxlength="200"/>
        </el-form-item>
        <el-form-item label="延期至" prop="latestTime">
          <el-date-picker v-model="form.latestTime" placeholder="请选择" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
                          style="width: 100%;"/>
        </el-form-item>
      </el-form>
    </template>
  </edit-dialog>
</template>

<script>
import EditDialog from "@/components/editDialog/index.vue";
import ApplyApproveUploadFile from "@/views/construction/project-application/review-components/ApplyApproveUploadFile";
import {ApplyApproveType} from "@/views/construction/project-application/projectUtil";
import {applyDelay, approveBeforeProjectStart, reviewApplyDelay} from "@/api/construction-project/projectManage";
import store from "@/store";

export default {
  name: "ApplyDelayDialog",
  components: {ApplyApproveUploadFile, EditDialog},
  props: {
    options: {
      type: Object,
      default: () => ({})
    }
  },
  inject: ["options"],
  data() {
    return {
      visible: false,
      form: {
        type: Object,
        default: () => ({})
      },
      rules: {
        deferReason: [
          {required: true, message: '请输入', trigger: ['blur', 'change']},
        ],
        latestTime: [
          {required: true, message: '请选择', trigger: ['blur', 'change']},
        ]
      },
      title: '申请延期',
      formType: undefined,
      ApplyApproveType,
      loading:false
    }
  },
  computed: {
    userInfo() {
      return store.state.user.userInfo
    },
  },
  methods: {
    open({row, formType, resolve}) {
      this.visible = true
      this.formType = formType
      this.resolve = resolve
      this.form = {
        applyType: 1,
        appllyPerson: {
          id: this.userInfo.userId,
          name: this.userInfo.name,
          organId: this.userInfo.organId,
          organName: this.userInfo.organName,
        },
        projectId: row.id,
        deferReason: undefined,
        applyTime: undefined,
      }
    },
    handleCancel() {
      this.$refs.applyApproveFormRef.resetFields()
      this.visible = false
    },
    handleSubmit() {
      let that = this
      that.$refs.applyApproveFormRef.validate(valid => {
        if (valid) {
          this.loading = true
          applyDelay(that.form).then(res => {
            that.$message.success('操作成功')
            that.resolve()
            that.visible = false
          }).finally(()=>{
            this.loading= false
          })
        }
      })
    },
  }
}
</script>

<style lang="less" scoped>
.upload-approve-form {

}
</style>
